package com.sense.kukoo.common.repo.kv.book_sequence

import com.sense.kukoo.common.repo.bean.BookSequenceBean
import com.sense.kukoo.common.repo.bean.SearchHistoryBean
import com.sense.kukoo.common.repo.kv.KukooKeyValueManager
import com.sense.kukoo.common.repo.kv.login_history.LoginHistory
import com.tencent.mmkv.MMKV

class BookSequenceImpl(val mmkv: MMKV){

    fun set(bookId:Long, asc:Int){
        val sequenceBean = mmkv.decodeParcelable(
                KukooKeyValueManager.KEY_BOOK_SEQUENCE,
                BookSequenceBean::class.java) ?: BookSequenceBean(hashMapOf())

        sequenceBean.mData.set(bookId, asc)
        mmkv.encode(KukooKeyValueManager.KEY_BOOK_SEQUENCE, sequenceBean)
    }

    fun get(bookId:Long):Int{
        val sequenceBean = mmkv.decodeParcelable(
                KukooKeyValueManager.KEY_BOOK_SEQUENCE,
                BookSequenceBean::class.java) ?: BookSequenceBean(hashMapOf())

        return sequenceBean.mData.get(bookId) ?: 1
    }

}